package com.example.common.util;

import com.example.common.enums.BusinessTypeEnum;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Random;

public class BusinessNoGenerator {

    /**
     * @param businessTypeEnum 业务类型枚举
     * @return 业务类型编码 + 日期 + 随机6位数
     * */
    public static String generate(BusinessTypeEnum businessTypeEnum){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHms");
        String date = LocalDateTime.now(ZoneOffset.of("+8")).format(formatter);
        //随机4位数
        int min = 1;
        int max = 999999;
        Random random = new Random();
        int r = random.nextInt(max - min) + min;
        return businessTypeEnum.getValue() + date + r;
    }
}

